﻿using System.Xml.Serialization;
using T4UtilityBelt.Serializers;

namespace T4UtilityBelt.DataDesigns
{
    
    [XDefaultProperty("Properties")]
    public class Entity : IXShouldSerialize
    {
        public Entity()
        {
            _properties = new PropertyCollection(this);
            ShouldSerialize = true;
        }

        public Entity(string name)
            : this()
        {
            Name = name;
            
        }

        public Entity(string name, string pluralName)
            : this(name)
        {
            PluralName = pluralName;
        }

        public Entity(string name, string pluralName, string listName)
            : this(name, pluralName)
        {
            ListName = listName;
        }
        
        [XIgnore]
        public bool ShouldSerialize { get; set; }

        [XIgnore]
        public EntityModel EntityModel { get; internal set; }

        public string Name { get; set; }

        public string ListName { get; set; }

        public string PluralName { get; set; }

        public GeneratorOptions GeneratorOptions { get; set; }

        private readonly PropertyCollection _properties;

        public PropertyCollection Properties
        {
            get { return _properties; }
        }

        internal void FixModel(EntityModel model)
        {
            foreach (Property property in Properties)
            {
                property.FixModel(model, this);
            }
        }

    }
}